package cn.innosmart.aq.view.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import cn.innosmart.aq.R;
import cn.innosmart.aq.customize.ZoomImageView;
import cn.innosmart.aq.util.ImageComTools;
import cn.innosmart.aq.view.activity.base.BaseActivity;

/**
 * Created by David on 2015/12/7.
 */
public class ShowWorkLogImageActivity extends BaseActivity {
    private final int EXIT = 0;
    String url;
    private Toolbar toolbar;
    private TextView tvTile;
    private ZoomImageView zoomImageView;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case EXIT:
                    exit();
                    break;
            }
        }
    };
    private Toolbar.OnMenuItemClickListener onMenuItemClick = new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Intent intent = getIntent();
            intent.putExtra("url", url);
            setResult(1003, intent);
            finish();
            return true;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_worklog_image);
        setBar();
        url = getIntent().getStringExtra("url");
        Bitmap rawBitmap1 = ImageComTools.scaleBitmap(url,640);
        zoomImageView = (ZoomImageView) findViewById(R.id.ziv);
        if (rawBitmap1 != null)
            zoomImageView.setImageBitmap(rawBitmap1);
    }

    private void setBar() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setNavigationIcon(R.drawable.toolbar_back);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setOnMenuItemClickListener(onMenuItemClick);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mHandler.sendEmptyMessage(EXIT);
            }
        });
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        getMenuInflater().inflate(R.menu.menu_work_log_image, menu);
        return super.onCreateOptionsMenu(menu);
    }
}
